//
//  BinaryTreeController.m
//  Objc进阶Demo
//
//  Created by Don't update on 2018/8/20.
//  Copyright © 2018年 Don't update. All rights reserved.
//

#import "BinaryTreeController.h"
#import "BinaryTree.h"
@interface BinaryTreeController ()
@property (nonatomic,strong)NSArray *dataSource;
@end

@implementation BinaryTreeController

-(NSArray *)dataSource{
    if (_dataSource == nil) {
        _dataSource = [[NSArray alloc]initWithObjects:@"12",@"1",@"3",@"20",@"54",@"19",@"2",@"23",@"23",@"11",nil];
    }
    return _dataSource;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self dataSource];
    BinaryTree *tree = [BinaryTree createTreeWithValues:_dataSource];
    
    [BinaryTree treeNodeAtIndex:5 inTree:tree];
    
    NSMutableArray *orderArray = [NSMutableArray array];
    [BinaryTree perOrderTraverseTree:tree handler:^(BinaryTree *treeNode) {
        [orderArray addObject:[NSString stringWithFormat:@"%lu",treeNode.Value]];
    }];
    NSLog(@"先序遍历 **************");
    NSLog(@"%@",[orderArray componentsJoinedByString:@","]);
    
    NSInteger depth = [BinaryTree depthOfTree:tree];
    NSLog(@"树深度:%lu",depth);
    
    NSInteger width = [BinaryTree widthOfTree:tree];
    NSLog(@"树宽度:%lu",width);
}



@end
